<?php
// 系统默认控制器
class TongjiAction extends SaleAction
{
    public function index()
    {
        $remarks = M('Remarks'); // 实例化模型类
        $id = I("session.userid");
        $con['adduser'] = $id;
        $con["_string"] = "TO_DAYS(lxtime)=to_days(now())";
        $list = $remarks->where($con)->select();

        $emps=$this->getMyEmployee(0);
        $this->assign('accounts_list',  $emps);
        $this->assign('all_list', $list);

        $this->display();
    }

    public function  bPage($totalnum, $pagedata)
    {
        $pagsize = 15;
        $page = new Page($totalnum, $pagsize);
        $page->rollPage = $pagsize;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $pagedata["pageshow"] = $pageshow;
    }

//统计单个员工
    public function yuangong()
    {
        $adduser = $this->_param(3); //获取GET的第三个参数，员工名称
        $leixing = $this->_param(5); //获取GET的第三个参数，员工名称
        $all = M('Custom');
        $zcount = $all->where("adduser = '$adduser'")->count();
        $this->assign('zcount', $zcount);
        //echo($zuotian);
        $ztcount = $all->where("adduser = '$adduser'  and addtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )
          AND   addtime   <  CURDATE()")->count();
        //echo $all->getLastSql();
        $this->assign('ztcount', $ztcount);
        $beizhu = M('Remarks');
        $bcount = $beizhu->where("adduser = '$adduser'  and lxtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )   AND   lxtime   <  CURDATE()")->count();
        //echo $beizhu->getLastSql();
        $this->assign('bcount', $bcount);
        $jtcount = $all->where("adduser = '$adduser'  and TO_DAYS(addtime) = TO_DAYS(NOW())")->count();
        //echo $all->getLastSql();
        $this->assign('jtcount', $jtcount);
        $jbeizhu = M('Remarks');
        $jbcount = $jbeizhu->where("adduser = '$adduser'  and TO_DAYS(lxtime) = TO_DAYS(NOW())")->count();
        //echo $jbeizhu->getLastSql();
        $this->assign('jbcount', $jbcount);
        $r = $all->count();
        import('ORG.Util.Page');
        $page = new Page($r, 20); //后台管理页面默认一页显示8条文章记录
        $page->setConfig('prev', "上一页"); //上一页
        $page->setConfig('next', '下一页'); //下一页
        $page->setConfig('first', '首页'); //第一页
        $page->setConfig('last', '尾页'); //最后一页
        $page->setConfig('theme', ' %first% %upPage%  %linkPage%  %downPage% %end%');
        //设置分页回调方法
        $show = $page->show();
        $firstpage = $page->firstRow;
        $lastpage = $page->listRows;
        if ($leixing == "zuo")
        {

            $tongji = $all->query("select *, (select content from ys_remarks where ys_remarks.customid = ys_custom.id ORDER BY rid desc limit 0,1) as `content` from ys_custom where ys_custom.adduser='$adduser'  and addtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )   AND   addtime   <  CURDATE()  order by ys_custom.id desc limit $firstpage,$lastpage");

        } else
        {

            if ($leixing == "jin")
            {
                $tongji = $all->query("select *, (select content from ys_remarks where ys_remarks.customid = ys_custom.id ORDER BY rid desc limit 0,1) as `content` from ys_custom where ys_custom.adduser='$adduser' and  TO_DAYS(addtime) = TO_DAYS(NOW())  order by ys_custom.id desc limit $firstpage,$lastpage");

            } else
            {

                $tongji = $all->query("select *, (select content from ys_remarks where ys_remarks.customid = ys_custom.id ORDER BY rid desc limit 0,1) as `content` from ys_custom where ys_custom.adduser='$adduser'  order by ys_custom.id desc limit $firstpage,$lastpage");

            }

        }
        $level = session('level');
        if ($level == "1")
        {
            $this->assign('zongde', 'bossindex'); // 数据列表变量赋值
        } else
        {
            $this->assign('zongde', 'index'); // 数据列表变量赋值
        }
        $this->assign('accounts_list', $list); // 数据列表变量赋值
        $this->assign('all_list', $tongji); // 数据列表变量赋值
        $this->assign('page_method', $show); //分页列表变量赋值
        $this->assign('adduser', $adduser); //分页列表变量赋值
        $this->display(); // 输出模板
    }


    public function bossindex()
    {
        $account = M('User'); // 实例化模型类
        $list = $account->query("select * from ys_user where level='7' or level='8'  order by id asc");
        $all = M('Custom');
        $r = $all->count();
        //分页显示文章列表，每页20篇文章
        import('ORG.Util.Page');
        $page = new Page($r, 20); //后台管理页面默认一页显示8条文章记录
        $page->setConfig('prev', "上一页"); //上一页
        $page->setConfig('next', '下一页'); //下一页
        $page->setConfig('first', '首页'); //第一页
        $page->setConfig('last', '尾页'); //最后一页
        $page->setConfig('theme', ' %first% %upPage%  %linkPage%  %downPage% %end%');
        //设置分页回调方法
        $show = $page->show();
        $firstpage = $page->firstRow;
        $lastpage = $page->listRows;
        $tongji = $all->query("select *, (select content from ys_remarks where ys_remarks.customid = ys_custom.id ORDER BY rid desc limit 0,1) as `content` from ys_custom  order by ys_custom.id desc limit $firstpage,$lastpage");
        $this->assign('accounts_list', $list); // 数据列表变量赋值
        $this->assign('all_list', $tongji); // 数据列表变量赋值
        $this->assign('page_method', $show); //分页列表变量赋值
        $this->display(); // 输出模板
    }

    public function beizhu()
    {
        $adduser = $this->_param(3); //获取GET的第三个参数，员工名称
        $leixing = $this->_param(5); //获取GET的第三个参数，员工名称
        $all = M('Custom');
        $zcount = $all->where("adduser = '$adduser'")->count();
        $this->assign('zcount', $zcount);
        //echo($zuotian);
        $ztcount = $all->where("adduser = '$adduser'  and addtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )   AND   addtime   <  CURDATE()")->count();
        //echo $all->getLastSql();
        $this->assign('ztcount', $ztcount);
        $beizhu = M('Remarks');
        $bcount = $beizhu->where("adduser = '$adduser'  and lxtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )   AND   lxtime   <  CURDATE()")->count();
        //echo $beizhu->getLastSql();
        $this->assign('bcount', $bcount);
        $jtcount = $all->where("adduser = '$adduser'  and TO_DAYS(addtime) = TO_DAYS(NOW())")->count();
        //echo $all->getLastSql();
        $this->assign('jtcount', $jtcount);
        $jbeizhu = M('Remarks');
        $jbcount = $jbeizhu->where("adduser = '$adduser'  and TO_DAYS(lxtime) = TO_DAYS(NOW())")->count();
        //echo $jbeizhu->getLastSql();
        $this->assign('jbcount', $jbcount);
        $id = session('id');
        $adduser = $this->_param(3); //获取GET的第三个参数，员工名称
        $leixing = $this->_param(5); //获取GET的第三个参数，备注类型
        $all = M('Remarks');
        $r = $all->count();
        //分页显示文章列表，每页20篇文章
        import('ORG.Util.Page');
        $page = new Page($r, 20); //后台管理页面默认一页显示8条文章记录
        $page->setConfig('prev', "上一页"); //上一页
        $page->setConfig('next', '下一页'); //下一页
        $page->setConfig('first', '首页'); //第一页
        $page->setConfig('last', '尾页'); //最后一页
        $page->setConfig('theme', ' %first% %upPage%  %linkPage%  %downPage% %end%');
        //设置分页回调方法
        $show = $page->show();
        $firstpage = $page->firstRow;
        $lastpage = $page->listRows;
        if ($leixing == "jin")
        {
            $tongji = $all->query("SELECT * FROM ys_remarks LEFT JOIN ys_custom ON ys_remarks.customid=ys_custom.id WHERE TO_DAYS(ys_remarks.lxtime) = TO_DAYS(NOW()) and ys_remarks.adduser='$adduser'  order by ys_remarks.rid desc limit $firstpage,$lastpage");
        } else
        {
            $tongji = $all->query("SELECT * FROM ys_remarks LEFT JOIN ys_custom ON ys_remarks.customid=ys_custom.id WHERE ys_remarks.lxtime   >=   DATE_SUB(CURDATE(),   INTERVAL   1   DAY   )   AND   ys_remarks.lxtime   <  CURDATE()  and ys_remarks.adduser='$adduser'  order by ys_remarks.rid desc limit $firstpage,$lastpage");
        }
        //echo($all->getLastsql());
        $level = session('level');
        if ($level == "1")
        {
            $this->assign('zongde', 'bossindex'); // 数据列表变量赋值
        } else
        {
            $this->assign('zongde', 'index'); // 数据列表变量赋值
        }
        $this->assign('accounts_list', $list); // 数据列表变量赋值
        $this->assign('all_list', $tongji); // 数据列表变量赋值
        $this->assign('page_method', $show); //分页列表变量赋值
        $this->assign('adduser', $adduser); //分页列表变量赋值
        $this->display(yuangong); // 输出模板
    }


}

?>